package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     修改护理计划
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult updateNursingPlan(
            @PathVariable("id") Long id,
            @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanDto.setId(id);
        nursingPlanService.updateNursingPlan(id,nursingPlanDto);
        return success();
    }

    /**
     删除护理计划
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable("id") Integer id){
        nursingPlanService.deleteNursingPlan(id);
        return success();
    }
    /**
     启用或禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("护理计划启用或禁用")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "id") @PathVariable("id") Integer id,//传入的ID是护理等级的ID
            @ApiParam(value = "状态") @PathVariable("status") Integer status
    ){
        logger.info("启用或禁用,请求参数：{},{}",id,status);

        boolean result = nursingPlanService.enableOrDisable(id, status);

        if (result) {
            return success("状态更改成功");
        } else {
            return error("状态更改失败，护理计划不存在或状态无效");
        }
    }
    /**
     * 查询所有护理计划
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult getAll(){
        List<NursingPlanVo> list = nursingPlanService.getAll();
        return success(list);
    }

    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add(@RequestBody
                              @ApiParam(value = "新增护理计划请求数据类") NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation("护理计划分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> nursingPlanPaginationQuery(String name, Integer pageNum, Integer pageSize, Integer status){
        PageResponse<NursingPlanVo> pageResponse=nursingPlanService.nursingPlanPaginationQuery(name,pageNum,pageSize,status);
        return success(pageResponse);
    }

    /**
     * 根据id查询护理计划
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> searchNursingPlanById(@PathVariable Integer id){
        NursingPlanVo nursingPlanVo=nursingPlanService.searchNursingPlanById(id);
        return success(nursingPlanVo);
    }
}
